//
//  ShoppingListViewController.m
//  CenturyInterconnection
//
//  Created by Tian Wei You on 16/4/18.
//  Copyright © 2016年 Shanghai DuRui Information Technology Company. All rights reserved.
//

#import "ShoppingListViewController.h"
#import "ShoppingListProductsTableViewCell.h"
#import "paySelectViewController.h"
#import "PayViewController.h"
#import "TransModeViewController.h"
#import "AddressListViewController.h"

#define ShoppingListProductsCell @"ShoppingListProductsTableViewCell"

@interface ShoppingListViewController ()<UITableViewDataSource,UITableViewDelegate,AddressListViewControllerViewControllerDelegate,TransModeViewControllerDelegate,UITextFieldDelegate,PaySelectDegete>


@property(nonatomic,strong)UITableView *tableView;

@property(nonatomic,strong)NSString *orderStr;

@property(nonatomic,strong)UIView *mainTopView;
@property(nonatomic,strong)UIView *topView;
@property(nonatomic,strong)UIView *topView2;

@property(nonatomic,strong)UILabel *namelabel;
@property(nonatomic,strong)UILabel *phoneLabel;
@property(nonatomic,strong)UILabel *addressLabel;
@property(nonatomic,strong)UILabel *shippingLabel;


@property(nonatomic,strong)UIButton *updateButton;


@property(nonatomic,strong)UITextField *codeTextfield;

@property(nonatomic,strong)UILabel *ValueSubLabel;
@property(nonatomic,strong)UILabel *ValueShipLabel;
@property(nonatomic,strong)UILabel *ValueTotalLabel;

@property(nonatomic,strong)NSArray *shipMethodArray;


@property(nonatomic,strong)NSString *addressStr;

//运输方式
@property(nonatomic,strong)NSString *sendID;
@property(nonatomic,strong)NSString *sendStr;
@property(nonatomic,strong)NSString * shipdill;

@property(nonatomic,strong)NSString *totalValue;

@property(nonatomic,strong)NSDictionary *shippingDic;


@property(nonatomic,strong)NSDictionary *onePayment;

@property(nonatomic,assign)float discount;

@end

@implementation ShoppingListViewController

-(UITableView *)tableView{
    if (!_tableView) {
        _tableView=[[UITableView alloc]initWithFrame:CGRectMake(ACTUAL_HEIGHT(0),ACTUAL_HEIGHT(75), KScreenWidth, KScreenHeight-ACTUAL_HEIGHT(118)) style:UITableViewStyleGrouped];
        _tableView.delegate=self;
        _tableView.dataSource=self;
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    }
    return _tableView;
}

-(UIView *)shippingLabel{
    if(!_shippingLabel){
        _shippingLabel=[[UILabel alloc]initWithFrame:CGRectMake(ACTUAL_WIDTH(15), 0, ACTUAL_WIDTH(320), ACTUAL_HEIGHT(40))];
        _shippingLabel.backgroundColor = [UIColor clearColor];
        _shippingLabel.font = FONT_SYSTEM_28;
        _shippingLabel.numberOfLines = 0;
    }
    return _shippingLabel;
}


#pragma mark - viewDidLoad
- (void)viewDidLoad {
    [super viewDidLoad];
    
    _discount = 0;
    self.view.backgroundColor=[UIColor whiteColor];
    
    [self makeNaviButton];
    [self makeView];
    
    [self getDatas];
    self.onePayment = [[NSDictionary alloc] init];
    
    [self shippingLabel];
    
    [self.tableView registerNib:[UINib nibWithNibName:ShoppingListProductsCell bundle:nil] forCellReuseIdentifier:ShoppingListProductsCell];
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"666"];
    [self.view addSubview:self.tableView];
    
    UITapGestureRecognizer *tapGr = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(viewTapped:)];
    tapGr.cancelsTouchesInView = NO;
    [self.view addGestureRecognizer:tapGr];
}

-(void)makeNaviButton{
    
    self.title=@"Process Order";
    
    UIButton *forkButton=[[UIButton alloc]initWithFrame:CGRectMake(ACTUAL_WIDTH(320), 0, ACTUAL_WIDTH(30), ACTUAL_HEIGHT(30))];
    [forkButton setImage:[UIImage imageNamed:@"nav_close"] forState:0];
    [forkButton addTarget:self action:@selector(comeBackToRoot) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem*item1 = [[UIBarButtonItem alloc]initWithCustomView:forkButton];
    self.navigationItem.rightBarButtonItem=item1;
    
    
    UIButton *leftButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [leftButton setBackgroundImage:[UIImage imageNamed:@"nav_back"] forState:0];
    leftButton.frame=CGRectMake(0, 0, ACTUAL_WIDTH(23), ACTUAL_HEIGHT(23));
    //forkButton.backgroundColor=[UIColor yellowColor];
    [leftButton addTarget:self action:@selector(comeBack) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem*item= [[UIBarButtonItem alloc]initWithCustomView:leftButton];
    self.navigationItem.leftBarButtonItem=item;
}

-(void)makeView{
    
    //mainTopView
    self.mainTopView=[[UIView alloc] initWithFrame:CGRectMake(0,ACTUAL_HEIGHT(0),KScreenWidth, ACTUAL_HEIGHT(100))];
    self.tableView.tableHeaderView = self.mainTopView;
    
    UIImageView *topView=[[UIImageView alloc]initWithFrame:CGRectMake(0,ACTUAL_HEIGHT(0),KScreenWidth, ACTUAL_HEIGHT(100))];
    [topView setImage:[UIImage imageNamed:@"topBackView"]];
    [self.mainTopView addSubview:topView];
    
    //topView
    _topView=[[UIView alloc]initWithFrame:CGRectMake(0,ACTUAL_HEIGHT(0),KScreenWidth, ACTUAL_HEIGHT(100))];
    
    UILabel *pleaseLabel=[[UILabel alloc]initWithFrame:CGRectMake(ACTUAL_WIDTH(40), ACTUAL_HEIGHT(36), ACTUAL_WIDTH(300), ACTUAL_HEIGHT(30))];
    pleaseLabel.text=@"Please Choose Shipping Address";
    pleaseLabel.font=FONT_SYSTEM_28;
    pleaseLabel.textColor = RGBACOLOR(102, 102, 102, 1);
    [_topView addSubview:pleaseLabel];
    
    //
    [self.mainTopView addSubview:_topView];
    
    //topView2
    _topView2=[[UIView alloc]initWithFrame:CGRectMake(0,ACTUAL_HEIGHT(0),KScreenWidth, ACTUAL_HEIGHT(100))];
    
    UIImageView *topView2=[[UIImageView alloc]initWithFrame:CGRectMake(0,ACTUAL_HEIGHT(0),KScreenWidth, ACTUAL_HEIGHT(100))];
    [topView setImage:[UIImage imageNamed:@"topBackView2"]];
    [_topView2 addSubview:topView2];
    
    _namelabel=[[UILabel alloc] initWithFrame:CGRectMake(ACTUAL_WIDTH(30), ACTUAL_HEIGHT(15),ACTUAL_WIDTH(150), ACTUAL_HEIGHT(30))];
    [_topView2 addSubview:_namelabel];
    
    _phoneLabel=[[UILabel alloc]initWithFrame:CGRectMake(ACTUAL_WIDTH(185), ACTUAL_HEIGHT(15), ACTUAL_WIDTH(175), ACTUAL_HEIGHT(30))];
    [_topView2 addSubview:_phoneLabel];
    
    _addressLabel=[[UILabel alloc]initWithFrame:CGRectMake(ACTUAL_WIDTH(30), ACTUAL_HEIGHT(35), ACTUAL_WIDTH(330), ACTUAL_HEIGHT(30))];
    [_topView2 addSubview:_addressLabel];
    
    //
    [self.mainTopView addSubview:_topView2];
    
    
    //地址跳转
    self.updateButton=[[UIButton alloc]initWithFrame:CGRectMake(ACTUAL_WIDTH(0), ACTUAL_HEIGHT(0), KScreenWidth, ACTUAL_HEIGHT(100))];
    [self.updateButton addTarget:self action:@selector(gotoUpdateAddress) forControlEvents:UIControlEventTouchUpInside];
    [self.mainTopView addSubview:self.updateButton];
 
    //提交订单
    UIButton *nextButton=[[UIButton alloc]initWithFrame:CGRectMake(ACTUAL_WIDTH(0), KScreenHeight-ACTUAL_HEIGHT(50), KScreenWidth, ACTUAL_HEIGHT(50))];
    [nextButton setTitle:@"Checkout" forState:UIControlStateNormal];
    nextButton.backgroundColor=[UIColor blackColor];
    [nextButton addTarget:self action:@selector(gotoPayProgess) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:nextButton];

}

#pragma mark - get ship data
-(void)getDatas{
    // http://viprunningonline.com/api/index.php? main_page=shipping_method
    NSString*urlStr=[NSString stringWithFormat:@"%@main_page=shipping_method",HTTP_ADDRESS];
    
    NSDictionary*params=@{@"zenid":[UserSession instance].cookie};
    HttpManager*manager=[[HttpManager alloc]init];
    
    [manager postDataFromNetworkWithUrl:urlStr parameters:params compliation:^(id data, NSError *error) {
        
        NSString*number=[NSString stringWithFormat:@"%@",data[@"status"]];
        
        if ([number isEqualToString:@"1"]) {
            self.shipMethodArray=data[@"data"];
        }
    }];

}

#pragma mark - checkout提交订单
-(void)gotoPayProgess{
    
    if (self.namelabel.text.length==0) {
        [JRToast showWithText:@"Please Choose Shipping Address！"];
        return;
    }
    
    if(self.onePayment == nil || self.onePayment[@"id"]==nil ){
        [JRToast showWithText:@"Please Choose Pay Method！"];
        return;
    }
    

     NSDictionary * params = [[NSDictionary alloc] init];
    
    if(self.codeTextfield.text.isEmpty == YES || self.codeTextfield.text == nil){
            params=@{@"act":@"set_payment",
                     @"payment":self.onePayment[@"id"],
                     @"zenid":[UserSession instance].cookie};
    }else{
        params=@{@"act":@"apply_coupon",
                 @"payment":self.onePayment[@"id"],
                 @"dc_redeem_code":self.codeTextfield.text,
                 @"zenid":[UserSession instance].cookie};
    }
    
    //http://viprunningonline.com/api/index.php?main_page=checkout_payment
    NSString * urlStr=[NSString stringWithFormat:@"%@main_page=checkout_payment",HTTP_ADDRESS];
    
    HttpManager * manager=[[HttpManager alloc] init];
    [manager postDataFromNetworkWithUrl:urlStr parameters:params compliation:^(id data, NSError *error) {
        
        NSString*number=[NSString stringWithFormat:@"%@",data[@"status"]];
        
        if ([number isEqualToString:@"1"]) {
            
            NSDictionary * order_total = [[NSDictionary alloc] initWithDictionary:data[@"order_total"]];
            
            for (NSArray *ar in order_total) {
                if([ar valueForKey:@"ot_total"]){
                    self.totalValue = [ar valueForKey:@"text"];
                }
            }
            if (self.totalValue) {
                NSDictionary *dict = @{@"index" : self.totalValue};
                [MobClick event:@"ProcessOrder_checkout" attributes:dict];
                
//                facebook提交订单统计
                [FBSDKAppEvents logEvent:@"CheckOutOrder" parameters:@{FBSDKAppEventParameterNameCurrency:[[NSUserDefaults standardUserDefaults]valueForKey:@"CURRENCY"],@"money":self.totalValue}];
            }
            
            //
            PayViewController *vc=[[PayViewController alloc]init];
            vc.allPrice = self.totalValue;
            [self.navigationController pushViewController:vc animated:YES];
       

        }else{
            [JRToast showWithText:data[@"status_message"] duration:2.0];
        }
    }];
    
}

#pragma mark - 运输方式选择
-(void)TransMethodSelected{
    // http://viprunningonline.com/api/index.php?main_page=checkout_shipping
    NSString*urlStr=[NSString stringWithFormat:@"%@main_page=checkout_shipping",HTTP_ADDRESS];
    NSDictionary *params = [[NSDictionary alloc]init];
    params=@{@"shipping":@"table_table",
                          @"address_book_id":[NSString stringWithFormat:@"%@",self.addressStr],
                          @"zenid":[UserSession instance].cookie};
    HttpManager*manager=[[HttpManager alloc]init];
    
    [manager postDataFromNetworkWithUrl:urlStr parameters:params compliation:^(id data, NSError *error) {
        
        NSString*number=[NSString stringWithFormat:@"%@",data[@"status"]];
        
        if ([number isEqualToString:@"1"]) {
            self.shippingDic=data[@"data"][@"shipping"];
            
            [self.tableView reloadData];
        }
    }];
    
}


#pragma mark - 设置tableview
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if (section==0) {
        return ACTUAL_HEIGHT(40);
    }
    if(section == 1){
        return ACTUAL_HEIGHT(0);
    }
    return 0.00001;
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return ACTUAL_HEIGHT(10);
}


#pragma mark -
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section==0) {
        return ACTUAL_HEIGHT(160);
    }
    
    return ACTUAL_HEIGHT(44);
}

#pragma mark -
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 4;
}


-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (section == 0) {
        return self.cartArray.count;
    }
    if(section == 3){
        return 4;
    }
    return 1;
}


- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    
    if (section == 0) {
        UIView *BGView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth, ACTUAL_HEIGHT(40))];
        BGView.backgroundColor=[UIColor whiteColor];
        
        UILabel *titleLabel=[[UILabel alloc]initWithFrame:CGRectMake(ACTUAL_WIDTH(15), ACTUAL_HEIGHT(0), ACTUAL_WIDTH(200), ACTUAL_HEIGHT(40))];
        titleLabel.text=@"Product List";
        titleLabel.font = FONT_SYSTEM_36;
        [BGView addSubview:titleLabel];
        
        return BGView;
    }
    
        return nil;
}


-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    UITableViewCell * cell=[tableView cellForRowAtIndexPath:indexPath];
    if (cell == nil) {
        cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];
        cell.selectionStyle=UITableViewCellSelectionStyleNone;
    }
    
    if(indexPath.section == 0){
        
        UITableViewCell *shopCell=[tableView dequeueReusableCellWithIdentifier:ShoppingListProductsCell];
        shopCell.selectionStyle = UITableViewCellSelectionStyleNone;
        
        UIImageView *imageView1=[shopCell viewWithTag:1];
        [imageView1 sd_setImageWithURL:[NSURL URLWithString:self.cartArray[indexPath.row][@"products_image"]] placeholderImage:nil];
        imageView1.backgroundColor = [UIColor whiteColor];
        imageView1.clipsToBounds = YES;
        imageView1.contentMode = UIViewContentModeScaleAspectFit;
        
        UILabel *label2=[shopCell viewWithTag:2];
        label2.text=self.cartArray[indexPath.row][@"products_name"];
        label2.font = FONT_SYSTEM_28;
        
        UILabel *label3=[shopCell viewWithTag:3];
        label3.text=self.cartArray[indexPath.row][@"format_total_price"];
        label3.textColor = RGBACOLOR(255, 42, 42, 1);
        label3.font = FONT_SYSTEM_24;
        
        UILabel *label4=[shopCell viewWithTag:4];
        label4.font = FONT_SYSTEM_24;
        label4.textColor = RGBACOLOR(204, 204, 204, 1);
        if ([self.cartArray[indexPath.row][@"attributes"] count]==0) {
            label4.text=@"";
        }else{
            label4.text=self.cartArray[indexPath.row][@"attributes"][0][@"products_options_values_name"];
        }
        
        return shopCell;
    }
    
    if(indexPath.section == 1){
        if (self.onePayment.count > 0 ) {
            cell.textLabel.text = [NSString stringWithFormat:@"Pay Method:   %@",self.onePayment[@"title"]];
        }else{
            cell.textLabel.text = @"please choose pay method：";
        }
        cell.textLabel.font = FONT_SYSTEM_28;
    }
    
    if(indexPath.section == 2){
        
        if (self.shippingDic[@"title"]==nil) {
            self.shippingLabel.text=@"Shipping:Free shipping.    (you can change ship! please click here.)";
        }else{
            self.shippingLabel.text = [NSString stringWithFormat:@"Shipping:   %@", self.shippingDic[@"title"]];
        }
        [cell.contentView addSubview:self.shippingLabel];
    }
    
    if(indexPath.section == 3){
        
        if(indexPath.row == 0){
            
            self.codeTextfield=[[UITextField alloc]initWithFrame:CGRectMake(ACTUAL_WIDTH(15), ACTUAL_HEIGHT(5), ACTUAL_WIDTH(235), ACTUAL_HEIGHT(34))];
            self.codeTextfield.placeholder=@"CODE";
            self.codeTextfield.delegate=self;
            [cell.contentView addSubview:self.codeTextfield];
    
           
            UIButton *addButton=[[UIButton alloc]initWithFrame:CGRectMake(ACTUAL_WIDTH(280), ACTUAL_HEIGHT(5), ACTUAL_WIDTH(80), ACTUAL_HEIGHT(34))];
            [addButton setTitle:@"Apply" forState:0];
            addButton.backgroundColor=RGBCOLOR(88, 89, 89, 1);
            [addButton addTarget:self action:@selector(AddTheDiscountCode) forControlEvents:UIControlEventTouchUpInside];
            [cell.contentView addSubview:addButton];
            
        }
        
        if(indexPath.row == 1){
            //小计
            cell.textLabel.text=@"Subtotal:";

            cell.detailTextLabel.text=self.allPrice;
        }
    
        if(indexPath.row == 2){
            
            //航运
            cell.textLabel.text = @"Shipping:";
    
            if([self.shippingDic objectForKey:@"cost_format"]){
                cell.detailTextLabel.text = [self.shippingDic objectForKey:@"cost_format"];
            }else{
                cell.detailTextLabel.text = [self.shippingDic objectForKey:@"cost"];
            }
        }
        
        if(indexPath.row == 3){
            
            //总价 = 小计 + 航运
            cell.textLabel.text = @"Total:";
            if([self.shippingDic objectForKey:@"cost_format"]){
                
                CGFloat allCost = [self stringByReplaceWithStr:self.allPrice].floatValue +
                [[self stringByReplaceWithStr:self.shippingDic[@"cost_format"] ]floatValue ] - _discount;
                cell.detailTextLabel.text = [NSString stringWithFormat:@"%@%.2f",[self stringWithMoney],allCost];
                
            }else{
                
                CGFloat allCost = [self stringByReplaceWithStr:self.allPrice].floatValue +
                [[self stringByReplaceWithStr:self.shippingDic[@"cost"] ]floatValue ] - _discount;
                cell.detailTextLabel.text = [NSString stringWithFormat:@"%@%.2f",[self stringWithMoney],allCost];
            }
            self.totalValue = cell.detailTextLabel.text;
        }
    }
    
    return cell;
}

-(NSString *)stringByReplaceWithStr:(NSString *)string
{
    NSString * str = [[[[[[[string stringByReplacingOccurrencesOfString:@"$" withString:@""]stringByReplacingOccurrencesOfString:@"," withString:@""]stringByReplacingOccurrencesOfString:@"CAD" withString:@""]stringByReplacingOccurrencesOfString:@"£" withString:@""] stringByReplacingOccurrencesOfString:@"AU" withString:@""] stringByReplacingOccurrencesOfString:@"€" withString:@""] stringByReplacingOccurrencesOfString:@"-" withString:@""];
    return str;
}
-(NSString *)stringWithMoney
{
    NSString * str;
    NSString * moneyStr = [[NSUserDefaults standardUserDefaults] objectForKey:@"MONEYINDEX"];
    NSInteger index ;
    if ([moneyStr isEqualToString:@""]) {
        index = 1;
    }else{
        index = [moneyStr integerValue];
    }
    if (index == 0) {
        str = @"CAD$";
    }else if (index == 1){
        str = @"$";
    }else if (index == 2){
        str = @"£";
    }else if (index == 3){
        str = @"AU$";
    }else{
        str = @"€";
    }
    return str;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if(indexPath.section == 1){
        
        paySelectViewController * payselect = [[paySelectViewController alloc] init];
        payselect.delegate = self;
        [[SlideNavigationController sharedInstance] pushViewController:payselect animated:YES];
    }
    
    if (indexPath.section==2) {
        TransModeViewController *vc=[[TransModeViewController alloc]init];
        vc.sendArray=self.shipMethodArray;
        vc.delegate=self;
        [[SlideNavigationController sharedInstance] pushViewController:vc animated:YES];
    }
}


#pragma mark - 返回事件
-(void)comeBackToRoot{
    [self.navigationController popToRootViewControllerAnimated:YES];
    [[SlideNavigationController sharedInstance].rightMenu viewWillAppear:YES];
}

-(void)comeBack{
    ShoppingCarViewController * shopVC = [[ShoppingCarViewController alloc]init];
    [self.navigationController pushViewController:shopVC animated:NO];

}




#pragma mark - 跳转客户转运地址列表界面
-(void)gotoUpdateAddress{
    AddressListViewController *vc=[[AddressListViewController alloc]init];
    vc.delegate=self;
    [self.navigationController pushViewController:vc animated:YES];
}

//添加折扣码（默认银行卡支付）
-(void)AddTheDiscountCode{
    if (self.codeTextfield.text.length==0) {
        [JRToast showWithText:@"Please enter the discount code！" duration:2];
    }else{
    //http://viprunningonline.com/api/index.php?main_page=checkout_payment
    
    NSString*urlStr=[NSString stringWithFormat:@"%@main_page=checkout_payment",HTTP_ADDRESS];
        
    NSDictionary*params=@{@"act":@"apply_coupon",
                          @"payment":@"cp_pay",
                          @"dc_redeem_code":self.codeTextfield.text,
                          @"zenid":[UserSession instance].cookie};
        
    HttpManager*manager=[[HttpManager alloc]init];
    [manager postDataFromNetworkWithUrl:urlStr parameters:params compliation:^(id data, NSError *error) {
//        NSLog(@"++++++%@",data);
        NSString*number=[NSString stringWithFormat:@"%@",data[@"status"]];
        
        if ([number isEqualToString:@"1"]) {
            
            
            NSDictionary * dic = data[@"data"];
            
            NSArray * arr = dic[@"order_total"];
            if (arr.count == 4) {
                
                
                NSDictionary * discountDic = arr[2];
//                NSLog(@"dic>>>>>>>>>>%@",discountDic);
                
                NSString * value = discountDic[@"text"];
//                NSLog(@">>>>>>>>>%@",value);
                
                _discount = [[self stringByReplaceWithStr:value] floatValue];

            }
            
            [JRToast showWithText:@"Enter successfully！" duration:2];
            [self.tableView reloadData];
        }else{
            [JRToast showWithText:data[@"status_message"] duration:2];
        }
        
    }];
    }
}



#pragma mark - 代理  update
-(void)delegateForBack:(NSDictionary *)dict{
    _namelabel.text=dict[@"lastName"];
    _phoneLabel.text=dict[@"postCode"];
    _addressLabel.text=dict[@"streetAdress"];
    self.addressStr=dict[@"addressID"];
    self.topView.hidden = YES;
    
    //[self.mainTopView addSubview:self.topView2];
    
    [self TransMethodSelected];
}

//支付方式选择代理
-(void)paySelectDelegeMethod:(NSDictionary *)onePay{
    self.onePayment = onePay;
    
    [self.tableView reloadData];
}

//运费代理
-(void)cellOfTransMethodSelected:(NSString*)sendId AndTitle:(NSString *)title andShipPrice:(NSString *)shipPrice
{
    NSDictionary * data = @{@"cost":shipPrice,
                            @"id":sendId,
                            @"title":title};
    self.shippingDic = data;
    
    [self.tableView reloadData];
}


#pragma mark - 滚动tableview的时候收起键盘
-(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{
    [self.view endEditing:YES];
}

#pragma mark - 键盘收回
-(void)viewTapped:(UITapGestureRecognizer*)tapGr
{
    [self.view endEditing:YES];
}

-(BOOL)textFieldShouldBeginEditing:(UITextView *)textView{
    [UIView animateWithDuration:0.25 animations:^{
        [self.tableView setY:self.tableView.y-75];
    }];
    return YES;
}

-(BOOL)textFieldShouldEndEditing:(UITextView *)textView{
    [UIView animateWithDuration:0.25 animations:^{
        [self.tableView setY:self.tableView.y+75];
    }];
    return YES;
}



#pragma mark -
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
